package com.huawei.appmarket.oobe.app;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import androidx.annotation.RequiresApi;
import com.huawei.secure.android.common.intent.SafeIntent;
import o.dkz;
import o.dld;
import o.dli;
import o.dlm;
import o.dlo;
import o.Logger;
import o.dof;
import o.ll;

@RequiresApi(api = 21)
public class OOBEExportedReceiver extends BroadcastReceiver {
    public static void doPrimaryFlowAfterSetupFinished(Context context) {
        if (dld.ˎ().ᐝ().isEmpty()) {
            dld.ˎ().ˎ(true);
        } else {
            dlm.ˋ();
            dlm.ˊ();
            dld.ˎ().ˎ(false);
        }
        dli.ˊ(context).edit().putBoolean("isPrimaryFlowSkipped", dld.ˎ().ॱॱ()).commit();
    }

    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
            SafeIntent safeIntent = new SafeIntent(intent);
            String action = safeIntent.getAction();
            Logger.ˎ("OOBE", "OOBEExportedReceiver action:" + action);
            if (action != null) {
                boolean z = true;
                switch (action.hashCode()) {
                    case -1839409797:
                        if (action.equals("com.huawei.appmarket.oobe.ACTION_SETUP_WIZARD_FINISHED")) {
                            z = false;
                            break;
                        }
                        break;
                    case -1762509884:
                        if (action.equals("com.huawei.appmarket.oobe.ACTION_QUEREY_IF_OOBE_SUPPORT")) {
                            z = true;
                            break;
                        }
                        break;
                    case -1541030203:
                        if (action.equals("com.huawei.appmarket.oobe.ACTION_PRIMARY_FLOW_SKIPPED")) {
                            z = true;
                            break;
                        }
                        break;
                    case -1242666123:
                        if (action.equals("com.huawei.appmarket.oobe.ACTION_NOTIFICATION_REMOVED")) {
                            z = true;
                            break;
                        }
                        break;
                    case 1692758417:
                        if (action.equals("com.huawei.appmarket.oobe.COTA_READY_FOR_SECONDARY_FLOW")) {
                            z = true;
                            break;
                        }
                        break;
                    case 1766038122:
                        if (action.equals("com.huawei.appmarket.oobe.ACTION_SETUP_WIZARD_ALLSET")) {
                            z = true;
                            break;
                        }
                        break;
                }
                switch (z) {
                    case false:
                        ॱ(context, safeIntent);
                        return;
                    case true:
                        ॱ(context);
                        return;
                    case true:
                        ॱ(safeIntent, context);
                        return;
                    case true:
                        if (!dli.ˏ(context)) {
                            return;
                        }
                        if (dld.ˎ().ॱᐝ()) {
                            Logger.ˎ("OOBE", "still querying, ignore");
                            return;
                        }
                        OOBESupportService.startService();
                        if (VERSION.SDK_INT >= 28) {
                            dli.ˊ(context, safeIntent);
                        }
                        Intent intent2 = new Intent("com.huawei.appmarket.oobe.ACTION_QUEREY_IF_OOBE_SUPPORT");
                        intent2.setClass(context, OOBEFlowController.class);
                        intent2.putExtra("fromWhere", 0);
                        ll.ˏ(context).ˋ(intent2);
                        dld.ˎ().ˊ(true);
                        return;
                    case true:
                        if (dli.ˏ(context)) {
                            if (VERSION.SDK_INT < 28) {
                                dli.ˊ(context, safeIntent);
                            }
                            dld.ˎ().ˎ(false);
                            dld.ˎ().ˏ(true);
                            dld.ˎ().ˎ(context);
                            return;
                        }
                        return;
                    case true:
                        Logger.ˎ("OOBE", "notification removed");
                        return;
                    default:
                        Logger.ˎ("OOBE", "default process");
                        return;
                }
            }
        }
    }

    private void ॱ(Context context) {
        if (dli.ˏ(context)) {
            dld.ˎ().ᐝ().clear();
            dld.ˎ().ˎ(true);
            dli.ˏ("350212", dli.ʽ(context));
        }
    }

    private void ॱ(Context context, SafeIntent safeIntent) {
        dlo.ˎ().ॱ();
        OOBESupportService.stopService();
        if (dli.ˏ(context)) {
            dli.ˏ("350203", dli.ʽ(context));
            boolean booleanExtra = safeIntent.getBooleanExtra("secondaryFlowNeedBroadcast", false);
            boolean booleanExtra2 = safeIntent.getBooleanExtra("isRegionSupport", false);
            dli.ˊ(context).edit().putBoolean("secondaryFlowNeedBroadcast", booleanExtra).putBoolean("isRegionSupport", booleanExtra2).putBoolean("setupwizardFinished", true).putBoolean("isPrimaryFlowSkipped", dld.ˎ().ॱॱ()).putLong("setupwizardFinishedTime", System.currentTimeMillis()).commit();
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("doWithSetupWizardFinished isPrimaryFlowSkipped=").append(dld.ˎ().ॱॱ()).append(", secondaryFlowNeedBroadcast=").append(booleanExtra).append(", isRegionSupport=").append(booleanExtra2);
            Logger.ˎ("OOBE", stringBuilder.toString());
            if (!booleanExtra) {
                if (booleanExtra2) {
                    dli.ʻ(context);
                }
                if (VERSION.SDK_INT >= 28) {
                    String stringExtra = safeIntent.getStringExtra("channelInfo");
                    if (!dof.ˋ(stringExtra)) {
                        dli.ˊ(context).edit().putString("channelInfo", stringExtra).commit();
                    }
                }
            }
            if (!dld.ˎ().ॱॱ()) {
                Logger.ˎ("OOBE", "doWithSetupWizardFinished doPrimaryFlowAfterSetupFinished");
                doPrimaryFlowAfterSetupFinished(context);
            }
            if (dld.ˎ().ॱॱ()) {
                Logger.ˎ("OOBE", "doWithSetupWizardFinished prepare notification flow");
                if (dli.ˏॱ(context)) {
                    if (dli.ˋ(context) == 2) {
                        dli.ˎ(context);
                    } else {
                        OOBEQueryIfSupportJobService.schedule(context, 1);
                    }
                }
            }
            dkz.ˎ();
            OOBEAppListUpdateCheckJobService.schedule(context);
        }
    }

    private void ॱ(SafeIntent safeIntent, Context context) {
        if (!dli.ˊ(context).getBoolean("isPrimaryFlowSkipped", false)) {
            return;
        }
        if (dli.ˏॱ(context)) {
            Logger.ˎ("OOBE", "cota is ok, return ");
            return;
        }
        dli.ˊ(context, safeIntent);
        OOBEQueryIfSupportJobService.schedule(context, 1);
    }
}
